<template>
  <div class="compayn-detail">
    <div class="menu-wrapper">
      <template
          v-for="item in menus"
      >
        <div
            :key="item.id"
            class="menu-item"
            :class="activeMenu === item.value && 'active'"
            @click="changeMenuTab(item)"
        >
          {{ item.label }}
        </div>
        <div class="sub-menu" v-if="'children' in item">
          <div
              class="sub-menu-item"
              :class="activeMenu === subMenu.value && 'active'"
              v-for="subMenu in item.children"
              :key="subMenu.id"
              @click="changeMenuTab(subMenu)"
          >
            {{ subMenu.label }}
          </div>
        </div>
      </template>
    </div>
    <div class="tab-content-wrapper">
      <div class="company-name">
        <img src="@/assets/house.png" alt="">
        <p>
          安徽楚江科技新材料股份有限公司
        </p>
        <p>
          A股丨002171.SZ
        </p>
      </div>
      <!--tab名称-->
      <div class="tab-title">{{ getCurrentTabTitle() }}</div>
      <!--子菜单名称-->
      <!--<div class="sub-tab-title" v-if="this.activeMenu > 1">{{ getTargetMenuTitle() }}</div>-->
      <div v-if="!loading">
        <!--工商信息-->
        <BusinessInfo key="BusinessInfo" v-if="activeMenu === 1"/>
        <!--成长能力-->
        <GrowthAbility key="GrowthAbility" v-if="activeMenu === 3"/>
        <!--盈利能力-->
        <Profitability key="Profitability" v-if="activeMenu === 4" />
        <!--运营能力-->
        <OperationCapability key="OperationCapability" v-if="activeMenu === 5" />
        <!--偿债能力-->
        <DebtPayingAbility key="DebtPayingAbility" v-if="activeMenu === 6" />
        <!--财务报表-->
        <FinancialStatement key="FinancialStatement" v-if="activeMenu === 7" />
      </div>
    </div>
  </div>
</template>

<script>
import { nanoid } from 'nanoid'
import BusinessInfo from '@/views/companyDetail/components/businessInfo.vue'
import GrowthAbility from '@/views/companyDetail/components/growthAbility.vue'
import Profitability from '@/views/companyDetail/components/Profitability.vue'
import OperationCapability from '@/views/companyDetail/components/OperationCapability.vue'
import DebtPayingAbility from '@/views/companyDetail/components/DebtPayingAbility.vue'
import FinancialStatement from '@/views/companyDetail/components/FinancialStatement.vue'

export default {
  name: "companyDetail",
  components: { BusinessInfo, GrowthAbility, Profitability, OperationCapability, DebtPayingAbility, FinancialStatement },
  data() {
    return {
      menus: [
        { label: "工商信息", value: 1, id: nanoid() },
        {
          label: "财务信息", value: 2, id: nanoid(), children: [
            {
              label: "成长能力",
              value: 3,
              id: nanoid()
            },
            {
              label: "盈利能力",
              value: 4,
              id: nanoid()
            },
            {
              label: "运营能力",
              value: 5,
              id: nanoid()
            },
            {
              label: "偿债能力",
              value: 6,
              id: nanoid()
            },
            {
              label: "财务报表",
              value: 7,
              id: nanoid()
            }
          ]
        }
      ],
      activeMenu: 1,
    }
  },
  mounted() {
    //this.activeMenu = 7 || this.menus[0].value
  },
  methods: {
    changeMenuTab(menu) {
      if (menu.value === 2) return
      this.activeMenu = menu.value
    },
    goBack() {
      this.$router.go(-1)
    },
    //查找当前顶级tab名称
    getCurrentTabTitle() {
      const currentMenu = this.menus.find(item => {
        return item.value === this.activeMenu || item?.children?.some(sub => sub.value === this.activeMenu)
      });
      return currentMenu?.label || ''
    },
    // 获取指定节点菜单名称
    getTargetMenuTitle() {
      return this.menus[1].children.find(item => item.value === this.activeMenu)?.label || ''
    }
  }
}
</script>

<style scoped lang="scss">
.compayn-detail {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 5px;
  display: flex;
  justify-content: flex-start;

  .menu-wrapper {
    width: 200px;
    height: 100%;
    padding: 13px;
    border-right: solid 1px rgba(234, 234, 234, 1);

    .menu-item, .sub-menu .sub-menu-item {
      width: 100%;
      height: 50px;
      padding: 0 12px;
      //background: #f9fafc;
      display: inline-flex;
      align-items: center;
      cursor: pointer;
      justify-content: space-between;
      align-items: center;
      font-size: 14px;
      color: #242424;

      &.active {
        background: #ebf1ff;
        color: #3878ff;
        &::after {
          content: ' ';
          width: 0;
          height: 0;
          border-top: 8px solid #3878FF;
          border-bottom: 8px solid transparent;
          border-left: 8px solid transparent;
          transform: rotate(45deg);
        }
      }
    }
    .menu-item {
      font-weight: 600;
    }

    .sub-menu .sub-menu-item {
      //padding-left: 40px;
      display: inline-flex;
      color: #5D5F62;
    }
  }

  .tab-content-wrapper {
    flex: 1;
    height: 100%;
    padding: 35px;

    .company-name {
      width: 100%;
      height: 72px;
      padding-bottom: 10px;
      padding-left: 78px;
      border-bottom: dashed 1px #E2E2E2;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: flex-start;
      position: relative;
      img {
        width: 62px;
        position: absolute;
        left: 0;
        top: 0;
      }
      p {
        color: #333333;
        font-weight: 600;
        font-size: 18px;
        &:nth-child(3) {
          font-size: 14px;
          font-weight: 400;
          color: #333333;
          margin-top: 4px;
        }
      }
    }

    .tab-title {
      margin-top: 35px;
      font-size: 15px;
      display: inline-flex;
      justify-content: flex-start;
      align-items: center;
      margin-bottom: 20px;

      &::before {
        content: ' ';
        width: 4px;
        height: 18px;
        margin-right: 10px;
        border-radius: 5px;
        background-color: #3878ff;
      }
    }
    .sub-tab-title {
      width: 100%;
      height: 48px;
      border-radius: 5px;
      padding: 0 16px;
      background-color: #fafbfd;
      font-size: 15px;
      line-height: 48px;
      margin-bottom: 20px;
    }
  }
}
</style>
